Rectangle: Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
w#include <fstream.h>
w#include <iostream.h>
wint main() {
w char str[10]; //Used later
w ofstream a_file("example.txt"); //Creates an instance of ofstream, and opens example.txt
w a_file<<"This text will now be inside of example.txt"; //Outputs to example.txt through a_file
w a_file.close(); //Closes up the file
w ifstream b_file("example.txt"); //Opens for reading the file
w b_file>>str; //Reads one string from the file cout<<str; //Should output ‘this'
w b_file.close();
w}
IOStream: Input/Output from file
Example